package com.ece.gui;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.ece.control.ConnexionController;

public class LoginFrame {
	
	private JFrame frame = new JFrame();
	private final JLabel errorLabel = new JLabel();
	private final JTextField login = new JTextField(25);
	private final JPasswordField pass = new JPasswordField(25);
	private final JButton validButton = new JButton("Sign in");
	
	
	public LoginFrame() {
		this.frame = new JFrame();
        this.frame.setSize(400, 200);
        this.frame.setLayout(new FlowLayout());
        
        this.errorLabel.setText("");
        this.frame.getContentPane().add(errorLabel);
        this.frame.getContentPane().add(new JLabel("Login"));
        this.frame.getContentPane().add(login);
        this.frame.getContentPane().add(new JLabel("Password"));
        this.frame.getContentPane().add(pass);
        
        this.validButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ConnexionController.checkCredentials(LoginFrame.this);
			}
        });
        this.frame.getContentPane().add(this.validButton);
	}
	
	public void show() {
		this.frame.setVisible(true);
	}
	
	public void hide() {
		this.frame.setVisible(false);
	}
	
	public void setErrorLabelText(String text) {
		this.errorLabel.setText(text);
	}
	
	public String getLogin() {
		return this.login.getText();
	}
	
	public String getPass() {
		return new String(this.pass.getPassword());
	}
}
